import axios from "axios";
import config from "../config";
import FormData from "form-data";

const request = axios.create({
	headers: {
		Authorization: config.NEW.TOKEN
	},
	timeout: 1000 * 60 * 30,
	baseURL: config.NEW.SERVER_URL
});

/** 上传文件 */
export const uploadFile = (data: FormData) => {
	return request({
		url: config.NEW.MINIO_FILE_UPLOAD,
		method: "post",
		data
	});
};

/** 素材保存 */
export const materialSave = (data: any) => {
	return request({
		url: "/api/m180/material/save",
		method: "post",
		data
	});
};


/** 素材分页 */
export const materialPage = (name: string) => {
	return request({
		url: "/api/m180/material/page",
		method: "get",
		params: {
			current: 1,
			size: 20,
			status: 0,
			isUnAudit: 1,
			name
		}
	});
};

/** 排期分页 */
export const planPage = (name?: string) => {
	return request({
		url: "/api/m180/plan/page",
		method: "get",
		params: {
			current: 1,
			size: 9999,
			status: 0,
			name,
		}
	});
};

/** 排期保存 */
export const planSave = (data: any) => {
	return request({
		url: "/api/m180/plan/save",
		method: "post",
		data
	});
};


/**
 * 根据设备code获取设备信息
 */
export const getDeviceInfoByCode = (code: string) => {
  return request({
    url: "/api/m180/device/api/getCode",
    method: "GET",
    params: {
      code,
    }
  });
};

/**
 * 设备保存
 */
export const deviceSave = (data: any) => {
  return request({
    url: "/api/m180/device/save",
    method: "POST",
    data,
  });
};

/**
 * 排期关联素材
 */
export const planMaterialPage = (planCode: string) => {
  return request({
    url: "/api/m180/plan/material/page",
    method: "GET",
    params: {
      current: -1,
			size: -1,
			planCode,
    }
  });
};

/**
 * 排期关联设备
 */
export const planDevicePage = (planCode: string) => {
  return request({
    url: "/api/m180/plan/device/page",
    method: "GET",
    params: {
      current: -1,
			size: -1,
			planCode,
    }
  });
};